package com.ppch.wuwamanus.tools;

import org.springframework.ai.tool.ToolCallback;
import org.springframework.ai.tool.ToolCallbacks;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 通过 allTools 方法初始化所有的自定义工具类，并转换为 ToolCallback
 */
@Configuration
public class ToolRegistration {

    //searchApi 库的 api-key，用于实现联网搜索
    @Value("${search-api.api-key}")
    private String searchApiKey;

    // pexels 图片搜索库的 api-key，用于搜索图片
    @Value("${pexels-api.api-key}")
    private String imageSearchAPiKey;

    /**
     * 对自定义的工具类进行初始化，并转换为 ToolCallback
     * @return ToolCallback[]
     */
    @Bean
    public ToolCallback[] allTools() {
        //初始化自定义工具类
        FileOperationTool fileOperationTool = new FileOperationTool();
        PDFGenerationTool pdfGenerationTool = new PDFGenerationTool();
        ResourceDownloadTool resourceDownloadTool = new ResourceDownloadTool();
        WebFetchTool webFetchTool = new WebFetchTool();
        //TODO：还剩45次免费调用次数，充值的话40$每月，太贵了
        //WebSearchTool webSearchTool = new WebSearchTool(searchApiKey);
        TerminateTool terminateTool = new TerminateTool();
        //AskHumanTool askHumanTool = new AskHumanTool();
        //ImageSearchTool imageSearchTool = new ImageSearchTool(imageSearchAPiKey);
        CardDrawingAnalysisTool cardDrawingAnalysisTool = new CardDrawingAnalysisTool();
        //转换为 ToolCallback
        return ToolCallbacks.from(
                fileOperationTool,
                pdfGenerationTool,
                resourceDownloadTool,
                webFetchTool,
                terminateTool,
                cardDrawingAnalysisTool
        );
    }
}
